<template>
  <div class="item" @click="itemClick">
    <div v-if="isActive" class="item-icon-img">
      <slot name="item-icon"></slot>
    </div>
    <div v-else class="item-icon-img">
      <slot name="item-icon-active"></slot>
    </div>
    <p :class="{active:!isActive}">
      <slot name="item-text"></slot>
    </p>
  </div>
</template>

<script>
  export default {
    name: "TabBarItem",
    props:{
      path:{
        type:String
      }
    },
    methods:{
      itemClick(){
        this.$router.replace(this.path)
      }
    },
    computed:{
      isActive(){
        return this.$route.path.indexOf(this.path)
      }
    }
  }
</script>

<style scoped>
  .item-icon-img img{
    width: 24px;
    height: 24px;
  }
  .item{
    margin-top: 5px;
    text-align: center;
    font-size: 14px;
  }
  .active{
    color: red;
  }

</style>